import Vue from 'vue'
import Router from 'vue-router'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'

console.log(store)
//没有指定webpackChunkName,每个组件打包成一个js文件
const Login = () => import('@/view/login/login.vue') // 登录
const register = () => import('@/view/login/register.vue') // 注册
const forgot = () => import('@/view/login/forgot.vue') // 找回密码

const layout = () => import('@/view/layout/index.vue') // layout
const mains = () => import('@/view/layout/mains.vue') // layout
// const Home1 = () => import('@/view/home/cpts/tablestyle.vue') // 首页1
const Home1     = () => import('@/view/home/index.vue') // 首页2
const Home2 = () => import('@/view/home/cpts/cardstyle.vue') // 首页2
const Home3 = () => import('@/view/home/index3.vue') // 首页3
const eqmtShow = () => import('@/view/home/cpts/eqmt.vue') // 设备详情


const Task = () => import('@/view/task/task.vue') // 任务
const myTask = () => import('@/view/worksheet/myTask/index.vue') // 安全隐患
const workInstall = () => import('@/view/worksheet/apply/index.vue') // 安装申请
const mpwx1 = () => import('@/view/mpwx/1.vue') // 
const mpwxbanner = () => import('@/view/mpwx/banner.vue') // 
const mpwx3 = () => import('@/view/mpwx/3.vue') // 
const mpwx4 = () => import('@/view/mpwx/4.vue') // 
const mpwx5 = () => import('@/view/article/about.vue') // 

const word1 = () => import('@/view/article/1.vue') // 
const word2 = () => import('@/view/article/2.vue') // 
const word3 = () => import('@/view/article/3.vue') // 
const word4 = () => import('@/view/article/4.vue') // 
const word5 = () => import('@/view/article/knowledge.vue') // 

const User = () => import('@/view/sys/user/index.vue') // 用户管理
const Role = () => import('@/view/sys/role/index.vue') // 
const Permission = () => import('@/view/sys/permission/index.vue') // 
const sys4 = () => import('@/view/sys/menu/index.vue') // 
// const sys5      = () => import('@/view/sys/5.vue') // 
const sys5 = () => import('@/view/sys/dept/index.vue') // 
const Job = () => import('@/view/sys/job/index.vue') // 
const dictionary = () => import('@/view/sys/dictionary/index.vue') // 
const log = () => import('@/view/sys/log/index.vue') // 操作日志


const equipmentByArea = () => import('@/view/equipment/index.vue') // 
const equipmentByGateway = () => import('@/view/gateway/index.vue') // 

const datasWran = () => import('@/view/datas/wran/index.vue') // 报警数据
const datasIng = () => import('@/view/datas/ing/index.vue') // 实时数据
const datasEd = () => import('@/view/datas/ed/index.vue') // 历史数据


const week = () => import('@/view/report/week/index.vue') // 周报
// const month           = () => import('@/view/report/month/index.vue') // 月报
const month = () => import('@/view/report/month/index.vue') // 月报
const monthShow = () => import('@/view/report/month/index.vue') // 月报
const history = () => import('@/view/report/history/index.vue') // 电子台账

const Banner = () => import('@/view/website/banner/index.vue') // 轮播图
const Industry = () => import('@/view/website/industry/index.vue') // 行业分类
const Workflow = () => import('@/view/website/workflow/index.vue') // 工作流配置
const Warning = () => import('@/view/website/warning/index.vue') // 报价配置
const orderCategory = () => import('@/view/website/orderCategory/index.vue') // 工单类型
const sms = () => import('@/view/website/sms/index.vue') // 短信管理
const email = () => import('@/view/website/email/index.vue') // 短信管理





const UserMine = () => import('@/view/personal/index.vue') // 用户信息

//指定了相同的webpackChunkName，会合并打包成y一个js文件
// /* webpackChunkName: 'grounpTest' */使用命名chunk，一个特殊的注释语法来提供 chunk name (需要 Webpack > 2.4)
// const test3 = ()=>import(/* webpackChunkName:'grounpTest' */ '@/components/test3.vue') 
// const test4 = ()=>import(/* webpackChunkName:'grounpTest' */ '@/components/test4.vue')
Vue.use(Router)

let router = new Router({
  routes: [{
      //重定向
      path: '*',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/forgot',
      name: 'forgot',
      component: forgot
    },
    {
      path: '/register',
      name: 'register',
      component: register
    },
    {
      path: '/monthShow/:id',
      name: 'monthShow',
      component: monthShow
    },
    {
      path: '/eqmtShow/:id',
      name: 'eqmtShow',
      component: eqmtShow
    },
    {
      path: '/layout',
      name: 'layout',
      component: layout,
      redirect: '/home',
      children: [{
          path: '/home',
          name: 'home',
          component: mains,
          redirect: '/home/card',
          children: [{
              path: '/home/card',
              name: 'card',
              meta:{
                iclass:"home"
              },
              component: Home1
            },
            {
              path: '/home/list',
              name: 'home2',
              meta:{
                iclass:"home"
              },
              component: Home2
            }
          ]
        },
        {
          path: '/work',
          name: 'work',
          component: mains,
          redirect: '/work/Install',
          children: [{
              path: '/work/myTask',
              name: 'myTask',
              meta:{
                iclass:"work"
              },
              component: myTask
            },
            {
              path: '/work/Install',
              name: 'Install',
              meta:{
                iclass:"work"
              },
              component: workInstall
            },
            {
              path: '/work/orderCategory',
              name: 'orderCategory',
              meta:{
                iclass:"work"
              },
              component: orderCategory
            },
            {
              path: '/work/workflow',
              name: 'Workflow',
              meta:{
                iclass:"work"
              },
              component: Workflow
            }
          ]
        },
        {
          path: '/mpwx',
          name: 'mpwx',
          component: mains,
          redirect: '/mpwx/banner',
          children: [{
              path: '/mpwx/1',
              name: 'mpwx1',
              meta:{
                iclass:"mpwx"
              },
              component: mpwx1
            },
            {
              path: '/mpwx/3',
              name: 'mpwx3',
              meta:{
                iclass:"mpwx"
              },
              component: mpwx3
            },
            {
              path: '/mpwx/4',
              name: 'mpwx4',
              meta:{
                iclass:"mpwx"
              },
              component: mpwx4
            },
            {
              path: '/mpwx/about',
              name: 'mpwx5',
              meta:{
                iclass:"mpwx",
              },
              component: mpwx5
            },
            {
              path: '/mpwx/banner',
              name: 'Banner',
              meta:{
                iclass:"mpwx"
              },
              component: Banner
            },
          ]
        },
        {
          path: '/system',
          name: 'system',
          component: mains,
          redirect: '/system/user',
          children: [{
              path: '/system/user',
              name: 'User',
              meta:{
                iclass:"system"
              },
              component: User
            },
            {
              path: '/system/role',
              name: 'Role',
              meta:{
                iclass:"system"
              },
              component: Role
            },
            {
              path: '/system/permission',
              name: 'Permission',
              meta:{
                iclass:"system"
              },
              component: Permission
            },
            {
              path: '/system/menu',
              name: 'menu',
              meta:{
                iclass:"system"
              },
              component: sys4
            },
            {
              path: '/system/dept',
              name: 'sys5',
              meta:{
                iclass:"system"
              },
              component: sys5
            },
            {
              path: '/system/job',
              name: 'Job',
              meta:{
                iclass:"system"
              },
              component: Job
            },
            {
              path: '/system/logs',
              name: 'logs',
              meta:{
                iclass:"system"
              },
              component: log
            },
            {
              path: '/system/dict',
              name: 'dictionary',
              meta:{
                iclass:"system"
              },
              component: dictionary
            },
            {
              path: '/system/industry',
              name: 'Industry',
              meta:{
                iclass:"system"
              },
              component: Industry
            }
          ]
        },
        {
          path: '/website',
          name: 'website',
          component: mains,
          redirect: '/website/warning',
          children: [
            {
              path: '/website/warning',
              name: 'Warning',
              meta:{
                iclass:"website"
              },
              component: Warning
            },
            {
              path: '/website/sms',
              name: 'sms',
              meta:{
                iclass:"website"
              },
              component: sms
            },
            {
              path: '/website/email',
              name: 'email',
              meta:{
                iclass:"website"
              },
              component: email
            }
          ]
        },
        {
          path: '/word',
          name: 'word',
          component: mains,
          redirect: '/word/1',
          children: [{
              path: '/word/1',
              name: 'word1',
              meta:{
                iclass:"word"
              },
              component: word1
            },
            {
              path: '/word/2',
              name: 'word2',
              meta:{
                iclass:"word"
              },
              component: word2
            },
            {
              path: '/word/3',
              name: 'word3',
              meta:{
                iclass:"word"
              },
              component: word3
            },
            {
              path: '/word/4',
              name: 'word4',
              meta:{
                iclass:"word"
              },
              component: word4
            },
            {
              path: '/word/knowledge',
              name: 'word5',
              meta:{
                iclass:"word"
              },
              component: word5
            },
          ]
        },
        {
          path: '/eqmt',
          name: 'eqmt',
          component: mains,
          redirect: '/eqmt/index',
          children: [{
              path: '/eqmt/index',
              name: 'equipmentByArea',
              meta:{
                iclass:"eqmt"
              },
              component: equipmentByArea
            },
            {
              path: '/eqmt/gateway',
              name: 'equipmentByGateway',
              meta:{
                iclass:"eqmt"
              },
              component: equipmentByGateway,
            }

          ]
        },
        {
          path: '/personal',
          name: 'usermine',
          component: mains,
          redirect: '/personal/mine',
          children: [{
              path: '/personal/mine',
              name: 'usermine',
              meta:{
                iclass:"personal"
              },
              component: UserMine
            },
            {
              path: '/personal/out',
              name: 'out',
              meta:{
                iclass:"personal"
              },
              component: Home3
            }
          ]
        },
        {
          path: '/datas',
          name: 'datas',
          component: mains,
          redirect: '/datas/ing',
          children: [{
              path: '/datas/ing',
              name: 'datasIng',
              meta:{
                iclass:"datas"
              },
              component: datasIng
            },
            {
              path: '/datas/wran',
              name: 'datasWran',
              meta:{
                iclass:"datas"
              },
              component: datasWran,
            },
            {
              path: '/datas/ed',
              name: 'datasEd',
              meta:{
                iclass:"datas"
              },
              component: datasEd,
            }
          ]
        },
        {
          path: '/report',
          name: 'report',
          component: mains,
          redirect: '/report/week',
          children: [{
              path: '/report/week',
              name: 'week',
              meta:{
                iclass:"report"
              },
              component: week
            },
            {
              path: '/report/month',
              name: 'month',
              meta:{
                iclass:"report"
              },
              component: month,
            },
            {
              path: '/report/history',
              name: 'history',
              meta:{
                iclass:"report"
              },
              component: history,
            }
          ]
        },

        {
          path: '/task',
          name: 'task',
          component: Task
        }
      ]
    },
  ]
})
// // 拦截登录，token验证
router.beforeEach((to, from, next) => {
  nprogress.start();
  next();
  // if (to.meta.requireAuth === undefined) {
  //     if (store.state.token) {
  //         next()
  //     } else {
  //         next({
  //             path: '/login'
  //         })
  //     }
  // } else {
  //     next()
  // }
})
router.afterEach(() => {
  nprogress.done();
})
export default router
